<%
function HandleAnswer()
{
	//printFormContents();
	var sbmt = new String(Request.Item("sbmt.x"));
	var bck = new String(Request.Item("bck.x"));
	var rndzvs = new String(Request.Item("rndzvs.x"));
	var endBtn = new String(Request.Item("end.x"));
	
	var questionNames = new String(Request.Item("questionID")).split(",");
	var questionTypes = new String(Request.Item("questionType")).split(",");
	
	if(bck.length>0 && bck != "undefined")
	{
		interview.previousQuestion(new String(questionNames[0]).trim());
		return true;
	}
	if(rndzvs.length>0 && rndzvs != "undefined")
	{
		FINISH_INTERVIEW_RENDEZVOUS();
		Response.End();
	}
	if(endBtn.length>0 && endBtn != "undefined")
	{
		FINISH_INTERVIEW_INTERRUPT();
		Response.End();
	}
	
	if(sbmt.length > 0 && sbmt != "undefined")
	{
	    var firstEmptyQuestionID = "";
	    
	    for(var questionNameIndex = 0; questionNameIndex < questionNames.length; questionNameIndex++)
	    {
	        var saveAnswer = true;
	        
		    interview.setQuestionAsProcessed(questionNames[questionNameIndex].trim());
		    var targetQuestionID = new String(Session("user_targetQuestionID"));
		    var answerSetAvailable = (targetQuestionID.length == 0) || (targetQuestionID == "undefined");
            
            var qID = new String(questionNames[questionNameIndex]).trim();
            var qType = new String(questionTypes[questionNameIndex]).trim();
		    var questionObject = interview.Question(qID);
		    
		    if(qType != "TEXT")
		    {
			    if
			    (
			        qType == "SINGLE"
			        ||
			        qType == "SINGLE_OPEN"
		            ||
			        qType == "MULTIPLE_OPEN"
			    )
			    {
				    if(qType == "SINGLE")
				    {
					    var answerCheck = new String(Request.Item(qID));
					    if(answerCheck.length==0 || answerCheck=="undefined")
					    {
						    answerCheck = String(Request.Item(qID+"OTHER"));
						    if(answerCheck.length==0 || answerCheck=="undefined")
						    {
						        saveAnswer = false;
						        if(!questionObject.isOptional)
						        {
						            firstEmptyQuestionID = qID;
						        }
						    }
					    }
				    }
				    else
				    {
					    var answerCheck = String(Request.Item(qID+"OTHER"));
					    if(answerCheck.length==0 || answerCheck=="undefined")
					    {
					        saveAnswer = false;
				            if(!questionObject.isOptional)
				            {
	    				        firstEmptyQuestionID = qID;
	    				    }
					    }
				    }
				    
				    if(saveAnswer)
				    {
				        if(new String(Request.Item(qID)) != "undefined")
				        {
					        if(answerSetAvailable)
					        {
						        interview.setAnswer(qID, new String(Request.Item(qID)), new String("" + Request.Item(qID+"OTHER")));
						    }
				        }
				        else
				        {
					        if(answerSetAvailable)
					        {
						        interview.setAnswer(qID, "", new String("" + Request.Item(qID+"OTHER")));
						    }
				        }
				    }
			    }
			    else if(qType == "MULTIPLE")
			    {
				    var answer = new String("");
				    for(var i = 1; i<= Request.Form.Count; i++)
				    {
					    var qLen = qID.length;
					    var sAnswer = new String(Request.Form.Key(i));
					    if(sAnswer.substr(0, qLen) == qID && sAnswer != (qID + "OTHER"))
					    {
						    var optValue = sAnswer.substring(qLen, sAnswer.length);
						    answer += optValue;
					    }
				    }
				    if(answer.length==0 || answer == "undefined")
				    {
					    var openAnswer=new String(Request.Item(qID+"OTHER"));
					    if(openAnswer.length==0 || openAnswer == "undefined")
					    {
					        saveAnswer = false;
				            if(!questionObject.isOptional)
				            {
	    				        firstEmptyQuestionID = qID;
	    				    }
					    }
				    }
				    
				    if(saveAnswer)
				    {
				        if(answerSetAvailable)
				        {
					        interview.setAnswer(qID, answer, new String(Request.Item(qID+"OTHER")));
					    }
					}
			    }
			}

			checkQoutas();
		}
		
		if(firstEmptyQuestionID != "")
		{
            interview.setPosition(firstEmptyQuestionID, false);
            REDIRECT_TO_PAGE("?screenType=intervieweeInInterview&msg=SORU BOS GECILEMEZ")
            Response.End();
            return 0;
        }		
	}
}
%>